package com.zhijian.medical.controller;

import com.zhijian.entity.PageVo;
import com.zhijian.medical.entity.vo.request.AgentiaSearchBmVo;
import com.zhijian.medical.entity.vo.request.RoutinePathologyBmSaveOrUpdateVo;
import com.zhijian.medical.entity.vo.request.RoutinePathologyBmSearchVo;
import com.zhijian.medical.entity.vo.request.RoutineSingleSampleSearchVo;
import com.zhijian.medical.entity.vo.response.AgentiaBmVo;
import com.zhijian.medical.entity.vo.response.RoutinePathologyBmInfoVo;
import com.zhijian.medical.entity.vo.response.RoutinePathologyBmVo;
import com.zhijian.medical.entity.vo.response.RoutineSingleSampleVo;
import com.zhijian.medical.holder.CurrentUserHolder;
import com.zhijian.medical.service.AgentiaService;
import com.zhijian.medical.service.CacheService;
import com.zhijian.medical.service.RoutinePathologyBmService;
import com.zhijian.medical.service.RoutineSingleSampleService;
import com.zhijian.medical.util.Page;
import com.zhijian.response.annotation.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 常规病例包埋 控制层
 *
 * @author auto
 * @version 1.0
 * @date 2024-06-23 14:54:15
 */
@Slf4j
@Controller
@Api(tags = "常规病理-包埋")
public class RoutinePathologyBmController {

    @Autowired
    private RoutinePathologyBmService service;

    @Autowired
    private CacheService cacheService;

    @Autowired
    private AgentiaService agentiaService;

    @Autowired
    private RoutineSingleSampleService singleSampleService;

    /**
     * 获取脱水详情
     * @return
     */
    @Response
    @GetMapping("/routine/pathology/bm/info/{numbs}")
    @ApiOperation("获取包埋详情/蜡块号输入")
    public RoutinePathologyBmInfoVo pathologyInfo(@ApiParam(name = "numbs", value = "蜡块号") @PathVariable("numbs") String numbs) {
        log.info("{} | query info", this.getClass().getSimpleName());
        return service.pathologyInfo(numbs);
    }

    /**
     * 结束包埋
     * @return
     */
    @Response
    @GetMapping("/routine/pathology/bm/end")
    @ApiOperation("结束包埋")
    public boolean pathologyInfo() {
        log.info("{} | end baomai", this.getClass().getSimpleName());
        cacheService.del("gl_baomai:" + CurrentUserHolder.getUser().getId());
        return true;
    }

    /**
     * 样本详情
     * @return
     */
    @Response
    @GetMapping("/routine/pathology/bm/sample")
    @ApiOperation("样本详情")
    public List<RoutineSingleSampleVo> pathologySampleInfo() {
        log.info("{} | yangben query", this.getClass().getSimpleName());
        String s = cacheService.get("gl_baomai:" + CurrentUserHolder.getUser().getId());
        if (StringUtils.isBlank(s)) {
            return new ArrayList<>();
        }
        List<String> split = Arrays.asList(s.split(","));
        return singleSampleService.selectList(RoutineSingleSampleSearchVo.builder().numberList(split).build());
    }

    /**
     * 获取脱水详情
     * @return
     */
    @Response
    @PostMapping("/routine/pathology/bm/shila/page")
    @ApiOperation("添加蜡块")
    public Page<AgentiaBmVo> lakuaiInfo(@RequestBody(required = false) AgentiaSearchBmVo bmVo) {
        log.info("{} | query info", this.getClass().getSimpleName());
        return agentiaService.lakuaiInfo(bmVo);
    }

}